package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.AuditHistory;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AuditHistoryDao {

    /**
     * 查询
     *
     * @param auditType
     * @param relatedId
     * @return
     */
    @Results(id = "auditHistoryResultMap", value = {
            @Result(column = "audit_id", property = "auditId", jdbcType = JdbcType.INTEGER),
            @Result(column = "audit_type", property = "auditType", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "submit_user_id", property = "submitUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "audit_user_id", property = "auditUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "audit_status", property = "auditStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "audit_notes", property = "auditNotes", jdbcType = JdbcType.VARCHAR),
            @Result(column = "related_id", property = "relatedId", jdbcType = JdbcType.INTEGER),
    })
    @Select("select * from " + DB1TableName.AUDIT_HISTORY + " where audit_type = #{auditType} and related_id = #{relatedId} order by create_time desc")
    List<AuditHistory> getAuditHistory(@Param("auditType") Integer auditType, @Param("relatedId") Integer relatedId);

    /**
     * 新增
     *
     * @param auditHistory
     * @return
     */
    @Insert("Insert into " + DB1TableName.AUDIT_HISTORY + " (audit_type,create_time,submit_user_id,audit_user_id,audit_status,audit_notes,related_id) values " +
            " (#{auditHistory.auditType},#{auditHistory.createTime},#{auditHistory.submitUserId},#{auditHistory.auditUserId},#{auditHistory.auditStatus},#{auditHistory.auditNotes},#{auditHistory.relatedId})")
    Integer addAuditHistory(@Param("auditHistory") AuditHistory auditHistory);
}
